<?php
    $page_title = 'สถาบันภาษา BV Language : ข่าวการศึกษา';
    include('header.php');
    
    $sql = "SELECT td_value FROM text_data WHERE td_id=9";
    $result2 = $db->Execute($sql);
    
    include('function/db.tl.func.php');
    
    // PAGE LIMIT
    if(isset($_GET['p'])){
	$page = $_GET['p'];
    }else{
	$page = 1;
    }
    $PAGE_LIMIT = 10;
    $start_row = ($page-1)*$PAGE_LIMIT;
    
    $sql_relate = "SELECT news_id,title,intro,att_image FROM news WHERE is_active=1 AND show_main_page='Y' AND show_edu='Y' ORDER BY news_id DESC";
    
    $page_limit = $PAGE_LIMIT;
    $grouplimit = 10;
    $start_row = (($page-1))*$page_limit;
    $sql_relate_nolimit = $sql_relate;
    $sql_relate .= " LIMIT $start_row,$page_limit";
    $limitlink = '';
    // PAGE LIMIT END

    // PAGE LIMIT
    $count_row = $db->Execute($sql_relate_nolimit);
    $count_row2 = $count_row->NumRows();
    $count_row3 = ceil($count_row2/$page_limit) ;
    
    if($count_row3>1)
    {
	if($count_row3<$grouplimit)
	{
	    for($i = 1 ; $i<=$count_row3 ; $i++) {
		if($i==$page){
		    $limitlink .= $i."&nbsp;";
		}else{
		    $limitlink .= "<a href='news.php?p=$i'>&nbsp;$i&nbsp;</a>&nbsp;";
		}
	    }
	}
	else
	{
	    $pagegroup = ceil($page/$grouplimit); // Find group of current page
	    $allpagegroup = ceil($count_row3/$grouplimit); // Total page group
	    if($pagegroup==1) // If First Group
	    {
		if($page>1)
		{
		    $limitlink .= "<a href='news.php?p=".($page-1)."' title='Previous Page'>&nbsp;<&nbsp;previous&nbsp;</a>&nbsp;";
		}
		$i=($pagegroup*$grouplimit)-($grouplimit-1);
		$j=($pagegroup*$grouplimit);
		for($i ; $i<=$j ; $i++) {
		    if($i==$page){
			$limitlink .= $i."&nbsp;";
		    }else{
			$limitlink .= "<a href='news.php?p=$i'>&nbsp;$i&nbsp;</a>&nbsp;";
		    }
		}
		$limitlink .= "...&nbsp;<a href='news.php?p=".($page+1)."' title='Next Page'>&nbsp;next&nbsp;>&nbsp;</a>&nbsp;";
		$limitlink .= "<a href='news.php?p=$count_row3' title='Last Pages'>&nbsp;last&nbsp;>>&nbsp;</a>&nbsp;";
	    }
	    else if($pagegroup==$allpagegroup) // If Last Group
	    {
		$limitlink = "<a href='news.php?p=1' title='First Pages'>&nbsp;<<&nbsp;first&nbsp;</a>&nbsp;";
		$limitlink .= "<a href='news.php?p=".($page-1)."' title='Previous Page'>&nbsp;<&nbsp;previous&nbsp;</a>&nbsp;...&nbsp;";
		$i=($pagegroup*$grouplimit)-($grouplimit-1);
		$j=$count_row3;
		for($i ; $i<=$j ; $i++) {
		    if($i==$page){
			$limitlink .= $i."&nbsp;";
		    }else{
			$limitlink .= "<a href='news.php?p=$i'>&nbsp;$i&nbsp;</a>&nbsp;";
		    }
		}
		if($page<$count_row3)
		{
		    $limitlink .= "&nbsp;<a href='news.php?p=".($page+1)."' title='Next Page'>&nbsp;next&nbsp;>&nbsp;</a>&nbsp;";
		    $limitlink .= "<a href='news.php?p=$count_row3' title='Last Pages'>&nbsp;last&nbsp;>>&nbsp;</a>&nbsp;";
		}
	    }
	    else
	    {
		$limitlink = "<a href='news.php?p=1' title='First Pages'>&nbsp;<<&nbsp;first&nbsp;</a>&nbsp;";
		$limitlink .= "<a href='news.php?p=".($page-1)."' title='Previous Page'>&nbsp;<&nbsp;previous&nbsp;</a>&nbsp;...&nbsp;";
		$i=($pagegroup*$grouplimit)-($grouplimit-1);
		$j=($pagegroup*$grouplimit);
		for($i ; $i<=$j ; $i++) {
		    if($i==$page){
			$limitlink .= $i."&nbsp;";
		    }else{
			$limitlink .= "<a href='news.php?p=$i'>&nbsp;$i&nbsp;</a>&nbsp;";
		    }
		}
		$limitlink .= "...&nbsp;<a href='news.php?p=".($page+1)."' title='Next Page'>&nbsp;next&nbsp;>&nbsp;</a>&nbsp;";
		$limitlink .= "<a href='news.php?p=$count_row3' title='Last Pages'>&nbsp;last&nbsp;>>&nbsp;</a>&nbsp;";
	    }
	}
    }
    
    //echo $limitlink;
    
    $result = $db->Execute($sql_relate);
    $news_list = '';
    $i = 1;
    while (!$result->EOF)
    {
	$check = ($i++)%10;
	
	if($check==1)
	{
	    $news_list .= '<div>';
	}
	
	if(file_exists($iniVars['Locations']['tl_news_img_folder'].$result->fields['att_image']) AND $result->fields['att_image']!=NULL)
	{
	    $news_img = $iniVars['Locations']['tl_news_img_url'].$result->fields['att_image'];
	}
	else
	{
	    $news_img = $iniVars['Locations']['siteurl'].'images/news_no_img.jpg';
	}
	
	$newsIntro = strip_tags($result->fields['intro']);
	$news_list .= <<<sdl
	<div class="news_list">
	    <div class="news_list_img">
		<img src="{$news_img}" title="{$result->fields['title']}"/>
	    </div>
	    <div class="news_list_detail">
		<div class="news_list_detail_1">
		    {$result->fields['title']} {$result->fields['news_id']}
		</div>
		<div class="news_list_detail_2">
		    <a href="news_detail.php?news_id={$result->fields['news_id']}" class="aColorBox"><img src="images/news_readmore.jpg" /></a>
		</div>
		<div class="clear"></div>
	    </div>
	    <div class="clear"></div>
	</div>
sdl;
	if($check==0)
	{
	    $news_list .= '</div>';
	}
	
	$result->MoveNext();
    }
    include('function/db.func.php');
    
    $sql = "SELECT td_value FROM text_data WHERE td_id=6";
    $result = $db->Execute($sql);
    $result->Close();
?>
            <script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>
            <script type="text/javascript" src="js/jquery.colorbox-min.js"></script>
	    <link type="text/css" href="css/colorbox.css" rel="stylesheet" />
            <script>
                $(document).ready(function(){
                    //$('#news_list').cycle({
                    //    fx: 'scrollUp', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
                    //    pause:1,
                    //    delay: -500 
                    //});
		    
		    $(".aColorBox").colorbox({width:"770px", height:"90%"});
                });
            </script>
	    
	    <?php require('search.php'); ?>
	    
	    <a name="start" class="aAnchor">&nbsp;</a>
	    <div id="news_content" class="main_content">
		<div id="news_top_msg">
		    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;สถาบันภาษา <span class="text_color16">BV</span> <span class="text_color15">Language</span>  ขอเป็นผู้นำข่าวสารน่ารู้ต่างๆ ที่เป็นประโยชน์กับทุกคน ไม่ว่าจะเป็นข่าวการสอบวัดระดับความสามารถทางภาษา ข่าวการสอบทุนและการสอบแข่งขันต่างๆ ท่านที่สนใจสามารถนัดเวลา เพื่อเข้ารับการแนะแนวการศึกษา ได้ที่
		    <?php echo $result2->fields['td_value']; ?></div>
		<div id="news_content_l">
		    <img src="images/news_left_img.jpg" />
		</div>
		<div id="news_content_r">
		    <div id="news_list">
			<?php echo $news_list; ?>
			
			
			<!--<div id="news_list_nav"><?php echo $limitlink; ?></div>-->
		    </div>
		    <div id="news_list_nav"><?php echo $limitlink; ?></div>
		</div>
		<!--<div id="news_list_nav"><?php echo $limitlink; ?></div>-->
		<div class="clear"></div>
		
            </div>
            <div class="clear">&nbsp;</div>
            <!-- class main_content -->
<?
    include('footer.php');
?>